#!/bin/bash -e

function info() {
echo Usage: `basename $0` in.vcf
exit 65
}

while getopts  ":i:p:G" opts
do
        case  $opts  in
        i) intervals=$OPTARG;;
		p) out_prefix=$OPTARG;;
		G) somatic=true;;
		*) info;;
        esac
done
shift $(($OPTIND - 1))

if test -z "$1"; then info; fi


. /mnt/ilustre/app/medical/tools/.var
# nprot filter

echo gatk SelectVariants snp
java $tmp -jar $gatk \
-R $ref_genome \
-T SelectVariants \
-V $1 \
-o $out_prefix.snp.nprot.vcf \
-selectType SNP

echo gatk SelectVariants indel
java $tmp -jar $gatk \
-R $ref_genome \
-T SelectVariants \
-V $1 \
-o $out_prefix.indel.nprot.vcf \
-selectType INDEL

filter_clustered_mutations.pl $out_prefix.snp.nprot.vcf $out_prefix.indel.nprot.vcf

echo;echo;echo gatk CombineVariants
java $tmp -jar $gatk \
	-R $ref_genome \
	-T CombineVariants \
	--variant $out_prefix.snp.nprot.vcf.cluster_filtered.vcf \
	--variant $out_prefix.indel.nprot.vcf.cluster_filtered.vcf \
	-o $out_prefix.nprot.high.vcf \
	-genotypeMergeOptions UNSORTED
	
	
echo;echo;echo gatk CombineVariants
java $tmp -jar $gatk \
	-R $ref_genome \
	-T CombineVariants \
	--variant $out_prefix.snp.nprot.vcf.cluster_drop.vcf \
	--variant $out_prefix.indel.nprot.vcf.cluster_drop.vcf \
	-o $out_prefix.nprot.drop.vcf \
	-genotypeMergeOptions UNSORTED

format_filter_vcf.pl $out_prefix.nprot.drop.vcf nprot_cluster "nprot_cluster filter" > $out_prefix.nprot.low.vcf